import request from '../utils/request'

// 获取用户信息
export function getUserInfo(query) {
  return request({
    url: `/v1/user?user_id=${query}`,
    method: 'GET'
  })
}

// 更新用户头像
export function updateAvatar(data) {
  return request({
    url: '/v1/addimg/:avatar',
    method: 'POST',
    data
  })
}

// 获取收货地址列表
export function getAddresses(id) {
  return request({
    url: `/v1/users/${id}/addresses`,
    method: 'GET'
  })
}

// 删除收货地址
export function deleteAddress(user_id, address_id) {
  return request({
    url: `/v1/users/${user_id}/addresses/${address_id}`,
    method: 'DELETE'
  })
}

// 搜索地址
export function searchAddress(keyword) {
  return request({
    url: `https://elm.cangdu.org/v1/pois?keyword=${keyword}`,
    method: 'GET',
  })
}

// 增加收货地址
export function addAddress(data) {
  return request({
    url: `/v1/users/${data.user_id}/addresses`,
    method: 'POST',
    data
  })
}

// 可用红包
export function envelopes(user_id) {
  return request({
    url: `/promotion/v2/users/${user_id}/hongbaos?limit=20&offset=0`,
    method: 'get',
  })
}

// 过期红包
export function Expired(user_id) {
  return request({
    url: `/promotion/v2/users/${user_id}/expired_hongbaos?limit=20&offset=0`,
    method: 'get',
  })
}

//兑换红包
export function conversion(data) {
  return request({
    url: `/v1/users/${data.user_id}/hongbao/exchange`,
    method: 'POST',
    data
  })
}